package com.foreknow.eldclient.dao;

import com.foreknow.eldclient.po.Cart;
import org.apache.ibatis.annotations.Insert;
import org.apache.ibatis.annotations.Mapper;
import org.apache.ibatis.annotations.Update;
import org.springframework.stereotype.Repository;

import java.util.List;

@Mapper
@Repository
public interface CartMapper {
    /**
     * 添加一条购物车记录
     * @param cart
     * @return
     */
    @Insert("insert into Cart(cartId,foodId,businessId,userId,quantity) values(null,#{foodId},#{businessId},#{userId},1)")
     int saveCart(Cart cart);

    /**
     * 根据用户ID,商家ID，商品ID更新商品数量
     * @param cart
     * @return
     * @throws Exception
     */
    @Update("update Cart set quantity=#{quantity} where userId=#{userId} and businessId=#{businessId} and foodId=#{foodId}")
     int updateCart(Cart cart) throws Exception;

    /**
     * 删除一条购物车记录
     * @param cart
     * @return
     * @throws Exception
     */
     int removeCart(Cart cart) throws Exception;

    /**
     * 列出所以购物车记录
     * @param cart
     * @return
     * @throws Exception
     */
     List<Cart> listCart(Cart cart) throws Exception;
}
